//
//  PicCollectionViewCell.m
//  相册
//
//  Created by dllo on 16/9/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PhotoAlbumCollectionCell.h"
#import "UIView+Frame.h"
#import <AVFoundation/AVFoundation.h>
#import "Piclist.h"
#import "UIImageView+WebCache.h"
#import "NetImageSize.h"

@interface PhotoAlbumCollectionCell () <UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation PhotoAlbumCollectionCell

- (void)setPicList:(Piclist *)picList {
    _picList = picList;
    
//    UIImage *image = [UIImage imageNamed:];
//    _imageView.image = image;
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_picList.Url]];
    
    CGSize size = [NetImageSize downloadImageSizeWithURL:_picList.Url];
    
    
    CGRect boundingRect = CGRectMake(0, 0, self.contentView.dk_width, CGFLOAT_MAX);
    CGRect imageCurrentRect = AVMakeRectWithAspectRatioInsideRect(size, boundingRect);
    _imageView.frame = imageCurrentRect;
    _imageView.center = self.contentView.center;
    
}


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        _scrollView = [UIScrollView new];
        [self.contentView addSubview:_scrollView];
        _imageView = [UIImageView new];
        [_scrollView addSubview:_imageView];
        
        _scrollView.minimumZoomScale = 0.5;
        _scrollView.maximumZoomScale = 2.0;
        _scrollView.delegate = self;
    }
    return self;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return scrollView.subviews.firstObject;
}

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
    view.center = self.contentView.center;
//    NSLog(@"%@", view);
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _scrollView.frame = self.contentView.bounds;
}

- (void)prepareForReuse {
    [super prepareForReuse];
    _scrollView.zoomScale = 1.0;
}

@end
